import 'package:flutter/material.dart';
import 'package:goumao_app/Customs/gm_app_util.dart';
import 'package:package_info_plus/package_info_plus.dart';

class GMAboutMeScreen extends StatefulWidget {
  const GMAboutMeScreen({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _GMAboutMeScreenState createState() => _GMAboutMeScreenState();
}

class _GMAboutMeScreenState extends State<GMAboutMeScreen> {
  PackageInfo _packageInfo = PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
  );

  @override
  void initState() {
    super.initState();
    _initPackageInfo();
  }

  Future<void> _initPackageInfo() async {
    final info = await PackageInfo.fromPlatform();
    setState(() {
      _packageInfo = info;
    });
  }

  Widget _itemCell(String title, GestureTapCallback? onTap) {
    return Container(
      height: 60,
      padding: const EdgeInsets.fromLTRB(16, 0, 16, 0),
      child: InkWell(
        onTap: onTap,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  title,
                  style:
                      const TextStyle(color: Color(0xff333333), fontSize: 15),
                ),
                Image.asset(
                  "assets/images/gm_jx_icon@2x.png",
                  width: 16,
                  height: 16,
                )
              ],
            ),
            Container(
              height: 0.5,
              color: const Color(0xffeeeeee),
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: GMAppUtil.navText("关于我们"),
        elevation: 0,
      ),
      body: SafeArea(
        child: Column(
          children: [
            const SizedBox(
              height: 44,
            ),
            ClipRRect(
              borderRadius: BorderRadius.circular(8),
              child: Image.asset(
                'assets/images/logo.png',
                width: 100,
                height: 100,
              ),
            ),
            const SizedBox(
              height: 8,
            ),
            Text('${_packageInfo.appName} V${_packageInfo.version}',
                style: const TextStyle(
                    color: Color(0xff1a1a1a),
                    fontSize: 16,
                    fontWeight: FontWeight.w600)),
            const SizedBox(
              height: 50,
            ),
            _itemCell('隐私政策', () {
              GMAppUtil.gmShowTermServece(context, 1);
            }),
            _itemCell("用户协议", () {GMAppUtil.gmShowTermServece(context, 0);})
          ],
        ),
      ),
    );
  }
}
